package com.weasel.weixin.mp.servlet;

import com.weasel.helper.JsonHelper;
import com.weasel.weixin.mp.builder.MpConfigBuilder;
import com.weasel.weixin.mp.config.MpConfig;
import com.weasel.weixin.mp.request.WeiXinServerIpListRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutionException;

/**
 * Created by Dylan on 2015/9/28.
 */
public class WeiXinServerIpListServlet extends WeixinBaseServlet{


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        MpConfig config = MpConfigBuilder.fromXML("classpath:weixin-config.xml");
        try {
            List<String> ipList = new WeiXinServerIpListRequest(config).getIpList();
            response.getWriter().print(JsonHelper.toJsonString(ipList));
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
